<template>
  <div>
    <img src="../assets/images/help.png" alt class="img-help" />
    <div class="help container">
      <left-help-bar @getIssue="getIssueList"></left-help-bar>
      <div class="right">
        <div style="height:50px;"></div>
        <div class="line-ti">
          <div>帮助中心</div>
        </div>
        <div class="list-help" v-if="showIssueList">
          <ul>
            <li
              class="td-fbc a"
              @click="issueDetail(item.id)"
              v-for="(item,index) in issueList"
              :key="index"
            >
              <div class="td-f1">{{item.title}}</div>
              <span>{{item._add_time}}</span>
            </li>
          </ul>
        </div>

        <div class="issue-detail" v-else v-html="isDetail"></div>
      </div>
    </div>
  </div>
</template>

<script>
import leftHelpBar from "@components/leftHelpBar";
import { helpHome, helpInfo } from "@api/user";

export default {
  data() {
    return {
      showIssueList: true,
      issueList: [],
      isDetail: ""
    };
  },
  components: {
    leftHelpBar
  },
  methods: {
    issueDetail(id) {
      this.showIssueList = !this.showIssueList;
      let params = {
        id: id
      };
      helpInfo(params).then(
        res => {
          this.isDetail = res.data.content;
        },
        error => {
          this.$dialog.message(error.msg);
        }
      );
    },
    getIssueList(id = 1) {
      //获取问题列表
      let params = {
        cid: id
      };
      helpHome(params).then(
        res => {
          let list = res.data.list || [];
          this.issueList = list.map(item => {
            item._add_time = this.$formatDateTime(
              new Date(item.add_time * 1000)
            );
            return item;
          });
        },
        error => {
          this.$dialog.message(error.msg);
        }
      );
      this.showIssueList = true;
    }
  },
  mounted() {
    this.getIssueList();
  }
};
</script>

<style scoped  rel="stylesheet/scss" lang="scss" scoped>
$color: #DA213D;

.img-help {
  width: 100%;
  height: auto;
  margin-bottom: 20px;
}

.help {
  display: flex;
  padding-bottom: 160px;

  .right {
    width: 1000px;
    margin-left: 32px;

    .line-ti {
      width: 100%;
      border-bottom: 1px solid #dbdbdb;

      > div {
        color: #014a97;
        font-size: 18px;
        font-family: MicrosoftYaHei-Bold;
        border-bottom: 3px solid $color;
        width: 72px;
        line-height: 36px;
        font-weight: 600;
      }
    }

    .list-help {
      margin-top: 32px;

      ul {
        li {
          list-style-type: none;
          font-size: 16px;
          color: #333333;
          padding: 20px 0;
          border-bottom: dashed #eee 1px;
          cursor: pointer;
          > div {
            font-size: 15px;
            color: #333333;
          }
          > div:hover {
            color: $color;
          }
          > span {
            font-size: 13px;
            color: #999;
            display: block;
            width: 120px;
            text-align: right;
          }
        }
      }
    }
    .issue-detail{
      font-size: 15px;
      line-height: 2;
      color: #666;
      padding: 20px 10px;
      img{
        max-width: 100%;
      }
    }
  }
}
</style>
